package ricky.game
{
	import flash.utils.Dictionary;
	import flash.utils.setTimeout;
	
	import ricky.Interface.IAct;
	import ricky.Interface.IDispose;
	import ricky.Interface.IGraphic;
	import ricky.game.action.Act;
	
	/**
	 * 行动者
	 */
	public class Actor implements IDispose
	{
		public function Actor(graphic:IGraphic=null)
		{
			if(graphic)
				_graphic=graphic;
		}

		/**
		 * 用户数据
		 */			
		public function get data():Object
		{
			return _data;
		}

		public function set data(value:Object):void
		{
			_data = value;
		}

		public function set graphic(value:IGraphic):void
		{
			_graphic = value;
		}

//		/**
//		 * 逻辑计算
//		 */
//		public function action(timeline:Number):void
//		{
//				
//			if(this._isLock)
//				return;
//			
//			if(this._act)
//				_act.action(timeline);
//			
//		}
		
		/**
		 * 更新位置
		 */
		public function setPosition(x:Number,y:Number,z:Number):void
		{
			this.graphic.x=x;
			this.graphic.y=y;
			this.graphic.z=z;
		}

		public function set active(value:Boolean):void
		{
			_active = value;
			if(_active)
				this.playAnimAct();//.getGraphic(GraphicTypeEnum.MAIN).play();
			else
				this.graphic.stop();
		}
		
	
		
		/**
		 * 处理act
		 */
		public function processAct(type:int,par:*):void
		{
			
		}
		
		/**
		 * 播放动画行动
		 */
		public function playAnimAct(act:String=null):void
		{
			if(act!=null)
				_currAnimAct=act;
			
			playanimactbyname(_currAnimAct);
			
		}
		
		protected function playanimactbyname(act:String=null):void
		{
			this.graphic.playScene(act);
		}
		
		public function dispose():void
		{

		}
		
		/**
		 * 对象是否处于激活状态 控制动画播放
		 */		
		public function get active():Boolean
		{
			return _active;
		}
				
		/**
		 * 碰撞检测当碰到物体的时候调用</br>
		 * 格式function(objects:array):void objects为碰撞到得物体
		 */
		public function get onHitTestObject():Function
		{
			return _onHitTestObject;
		}

		public function set onHitTestObject(value:Function):void
		{
			_onHitTestObject = value;
		}


		
		public function get isLock():Boolean
		{
			return _isLock;
		}
		
		public function set isLock(value:Boolean):void
		{
			_isLock = value;
			if(_isLock==false)
			{
				if(_act)
				{
					_act.begin();
				}
			}
		}

		/**
		 * 控制器id标识
		 */
		public function set id(value:uint):void
		{
			_id=value;
		}		
		public function get id():uint
		{
			return _id;
		}
		
		/**
		 * 控制器名字
		 */
		public function set name(value:String):void
		{
			_name=value;
		}		
		
		/**
		 * 名字
		 */
		public function get name():String
		{
			return _name;
		}
		
		/**
		 * 对象是否处于死亡状态
		 */
		public function get isDead():Boolean
		{
			return _isDead;
		}
		
		public function set isDead(value:Boolean):void
		{
			_isDead = value;
		}
		
		/**
		 * 当前行动
		 */
		public function get act():Act
		{
			return _act;
		}
		
		/**
		 * 目标的类型用于寻路
		 */
		public function get asType():String
		{
			return _asType;
		}
		
		public function set asType(value:String):void
		{
			_asType = value;
		}
		
		/**
		 * 阵营
		 */
		public function get group():int
		{
			return _group;
		}
		
		public function set group(value:int):void
		{
			_group = value;
		}
		
		/**
		 * 到达目的地
		 */
		public function get onArrive():Function
		{
			return _onArrive;
		}
		
		/**
		 * 到达目的地
		 * function(this);
		 */
		public function set onArrive(value:Function):void
		{
			_onArrive = value;
		}
		
		/**
		 * 位置同步函数
		 */
		public function get stepFunction():Function
		{
			return _stepFunction;
		}
		
		/**
		 * @private
		 */
		public function set stepFunction(value:Function):void
		{
			_stepFunction = value;
		}
		
		/**
		 * 得到显示资源
		 * 控制的对象
		 */
		public function get graphic():IGraphic
		{
			return _graphic;
		}
		
		/**
		 * 移动调用函数
		 */
		public function get onMovingFun():Function
		{
			return _onMovingFun;
		}
		
		/**
		 * @private
		 */
		public function set onMovingFun(value:Function):void
		{
			_onMovingFun = value;
		}
		
		/**
		 * 当前播放的动画
		 */
		public function get currAnimAct():String
		{
			return _currAnimAct;
		}
		
		/**
		 * 物品的格子x世界坐标
		 */
		public function get gridX():int
		{
			_gridX=this.graphic.x/Common.tileWidth;
			return _gridX;//this.x/Common.tileWidth;
		}
		
		public function set gridX(value:int):void
		{
			this.graphic.x = value*Common.tileWidth;
			this._gridX=value;
		}
		
		/**
		 * 物品的格子Y世界坐标
		 * 或者是Z坐标
		 */
		public function get gridY():int
		{ 
			_gridY=this.graphic.y/Common.tileHeight;
			return _gridY;//this.y/Common.tileHeight;
		}
		
		public function set gridY(value:int):void
		{
			this.graphic.y = value*Common.tileHeight;
			_gridY=value;
		}
		//
		protected var _id:uint;
		protected var _name:String="";	
		protected var _currAnimAct:String="";
		protected var _data:Object;//用户数据
		protected var _asType:String;//目标的类型
		protected var _group:int;//阵营
		protected var _gridX:int;
		protected var _gridY:int;//
		
		private var _onHitTestObject:Function;//碰撞检测
		private var _onArrive:Function;//到达目的地s
		private var _stepFunction:Function;//位置同步函数
		protected var _onMovingFun:Function;//移动函数

		protected var _isLock:Boolean=false;
		private var _active:Boolean=true;//激活
		protected var _beginTime:int=0;//开始行动时间
		protected var _isDead:Boolean;//是否死亡
		
		protected var _act:Act;
		protected var _graphic:IGraphic;//ResoureGraphic;//动画图形资源

	}
}